<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Slice()和Splice()方法</title>
    <script>
        var arr = ["孙悟空","猪八戒","沙和尚","唐僧","白骨精"];

        //slipe()方法
        //提取元素
        var result=arr.slice(0,2);
        var result=arr.slice(4);
        var result=arr.slice(1,-2);

        console.log("result="+result);


        //splice()方法
        //删除和添加新元素
        var result=arr.splice(1,2,"牛魔王","铁扇公主");
        console.log(arr);
        console.log("result="+result);
        
         
    </script>
</head>
<body>
    
</body>
</html>